package edu.hawaii.halealohacli.command;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * Object to store data from a source.
 * Getters and setters are provided for the following:
 * name, time, carbonEmitted, energyConsumed, energyGenerated,
 * powerConsumed, and powerGenerated.
 * 
 * Comparators are also provided for each to allow sorting by the value, and then
 * by name assuming equal value.
 * 
 * @author Jordan Do
 */
public class SourceData {
  protected String name, time;
  protected double carbonEmitted, energyConsumed, energyGenerated;
  protected double powerConsumed, powerGenerated;
  protected List<Double> baseline = new ArrayList<Double>();

  /**
   * Constructor. Only takes the name because there are so many possible data points and each may
   * not be necessary. Should be manually added later.
   * 
   * @param name Name of source.
   */
  public SourceData(String name) {
    this.name = name;
  }

  // **********Setters*************
  /**
   * Setter.
   * 
   * @param x carbonEmitted
   */
  public void setCarbonEmitted(double x) {
    this.carbonEmitted = x;
  }

  /**
   * Setter.
   * 
   * @param x energyConsumed
   */
  public void setEnergyConsumed(double x) {
    this.energyConsumed = x;
  }

  /**
   * Setter.
   * 
   * @param x energyGenerated
   */
  public void setEnergyGenerated(double x) {
    this.energyGenerated = x;
  }

  /**
   * Setter.
   * 
   * @param x powerConsumed
   */
  public void setPowerConsumed(double x) {
    this.powerConsumed = x;
  }

  /**
   * Setter.
   * 
   * @param x powerGenerated
   */
  public void setPowerGenerated(double x) {
    this.powerGenerated = x;
  }

  /**
   * Setter.
   * 
   * @param time String
   */
  public void setTime(String time) {
    this.time = time;
  }

  /**
   * Setter.
   * 
   * @param x powerConsumed/Base Line
   */
  public void setBaseline(double x) {
      this.baseline.add(x);
  }
  
  // ********Getters***********
  /**
   * Getter.
   * 
   * @return String name
   */
  public String getName() {
    return this.name;
  }

  /**
   * Getter for time in a string representation.
   * 
   * @return String time
   */
  public String getTime() {
    return this.time;
  }

  /**
   * Getter.
   * 
   * @return double carbonEmitted;
   */
  public double getCarbonEmitted() {
    return this.carbonEmitted;
  }

  /**
   * Getter.
   * 
   * @return double energyConsumed
   */
  public double getEnergyConsumed() {
    return this.energyConsumed;
  }

  /**
   * Getter.
   * 
   * @return double energyGenerated
   */
  public double getEnergyGenerated() {
    return this.energyGenerated;
  }

  /**
   * Getter.
   * 
   * @return double powerConsumed
   */
  public double getPowerConsumed() {
    return this.powerConsumed;
  }

  /**
   * Getter.
   * 
   * @return double powerGenerated
   */
  public double getPowerGenerated() {
    return this.powerGenerated;
  }
  
  /**
   * Getter.
   * 
   * @return List<Double> baseline
   */
  public List<Double> getBaseline() {
    return this.baseline;
  }

  /**
   * A comparator.
   */
  public static final Comparator<SourceData> sortCarbonEmitted = new Comparator<SourceData>() {
    /**
     * Compares two SourceData objects by carbonEmittedSort.
     * 
     * @param x SourceData 1
     * @param y SourceData 2
     * @return int comparison results
     */
    public int compare(SourceData x, SourceData y) {
      double compared = x.getCarbonEmitted() - y.getCarbonEmitted();
      if (compared == 0) {
        return x.getName().compareTo(y.getName());
      }
      return (int) compared;
    }
  };
  /**
   * A comparator.
   */
  public static final Comparator<SourceData> sortEnergyConsumed = new Comparator<SourceData>() {
    /**
     * Compares two SourceData objects by energyConsumed.
     * 
     * @param x SourceData 1
     * @param y SourceData 2
     * @return int comparison results
     */
    public int compare(SourceData x, SourceData y) {
      double compared = x.getEnergyConsumed() - y.getEnergyConsumed();
      if (compared == 0) {
        return x.getName().compareTo(y.getName());
      }
      return (int) compared;
    }
  };
  /**
   * A comparator.
   */
  public static final Comparator<SourceData> sortEnergyGenerated = new Comparator<SourceData>() {
    /**
     * Compares two SourceData objects by energyGenerated.
     * 
     * @param x SourceData 1
     * @param y SourceData 2
     * @return int comparison results
     */
    public int compare(SourceData x, SourceData y) {
      double compared = x.getEnergyGenerated() - y.getEnergyGenerated();
      if (compared == 0) {
        return x.getName().compareTo(y.getName());
      }
      return (int) compared;
    }
  };
  /**
   * A comparator.
   */
  public static final Comparator<SourceData> sortPowerConsumed = new Comparator<SourceData>() {
    /**
     * Compares two SourceData objects by powerConsumed.
     * 
     * @param x SourceData 1
     * @param y SourceData 2
     * @return int comparison results
     */
    public int compare(SourceData x, SourceData y) {
      double compared = x.getPowerConsumed() - y.getPowerConsumed();
      if (compared == 0) {
        return x.getName().compareTo(y.getName());
      }
      return (int) compared;
    }
  };
  /**
   * A comparator.
   */
  public static final Comparator<SourceData> sortPowerGenerated = new Comparator<SourceData>() {
    /**
     * Compares two SourceData objects by powerGenerated.
     * 
     * @param x SourceData 1
     * @param y SourceData 2
     * @return int comparison results
     */
    public int compare(SourceData x, SourceData y) {
      double compared = x.getPowerGenerated() - y.getPowerGenerated();
      if (compared == 0) {
        return x.getName().compareTo(y.getName());
      }
      return (int) compared;
    }
  };
  /**
   * A comparator.
   */
  public static final Comparator<SourceData> sortName = new Comparator<SourceData>() {
    /**
     * Compares two SourceData objects by name.
     * 
     * @param x SourceData 1
     * @param y SourceData 2
     * @return int comparison results
     */
    public int compare(SourceData x, SourceData y) {
      return x.getName().compareTo(y.getName());
    }
  };
  /**
   * A comparator.
   */
  public static final Comparator<SourceData> sortTime = new Comparator<SourceData>() {
    /**
     * Compares two SourceData objects by time.
     * 
     * @param x SourceData 1
     * @param y SourceData 2
     * @return int comparison results
     */
    public int compare(SourceData x, SourceData y) {
      double compared = x.getTime().compareTo(y.getTime());
      if (compared == 0) {
        return x.getName().compareTo(y.getName());
      }
      return (int) compared;
    }
  };
}